<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*,java.io.*,java.sql.*,java.text.*, dbAccess.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>List of Visitations</title>
<link rel="stylesheet" type="text/css" href="css_files/style.css" />
<script type="text/javascript">
function changeNumberofDays(code)
{
	var mylist;
	if (code == "1")
	{
		mylist = document.forms["frmSearchByRange"].cmbStartMonth;
	}
	else if (code == "2")
	{
		mylist = document.forms["frmSearchByRange"].cmbEndMonth;
	}
	else
	{
		mylist = document.forms["frmCreateAppt"].cmbMonth;
	}
	var month = mylist.selectedIndex;
	if ((month == 0) || (month == 2) || (month == 4) || (month == 6) || (month == 7) || (month == 9) || (month == 11))
	{
		var days;
		if (code == "1")
		{
			days = document.forms["frmSearchByRange"].cmbStartDate;
		}
		else if (code == "2")
		{
			days = document.forms["frmSearchByRange"].cmbEndDate;
		}
		else
		{
			days = document.forms["frmCreateAppt"].cmbDate;
		}
		days.options.length = 0;
		var i = 1;
		for (i = 1; i <= 31; i++)
		{
			var opt = document.createElement("option");
			days.options.add(opt);
			opt.text = i;
			opt.value = i;
		}
	}
	else if (month == 1)
	{
		var days;
		if (code == "1")
		{
			days = document.forms["frmSearchByRange"].cmbStartDate;
		}
		else if (code == "2")
		{
			days = document.forms["frmSearchByRange"].cmbEndDate;
		}
		else
		{
			days = document.forms["frmCreateAppt"].cmbDate;
		}
		days.options.length = 0;
		var i = 1;
		for (i = 1; i <= 28; i++)
		{
			var opt = document.createElement("option");
			days.options.add(opt);
			opt.text = i;
			opt.value = i;
		}
	}
	else
	{
		var days;
		if (code == "1")
		{
			days = document.forms["frmSearchByRange"].cmbStartDate;
		}
		else if (code == "2")
		{
			days = document.forms["frmSearchByRange"].cmbEndDate;
		}
		else
		{
			days = document.forms["frmSearchByRange"].cmbDate;
		}
		days.options.length = 0;
		var i = 1;
		for (i = 1; i <= 30; i++)
		{
			var opt = document.createElement("option");
			days.options.add(opt);
			opt.text = i;
			opt.value = i;
		}
	}
}

	
</script>
</head>
<body>
<%
	String patientId = request.getParameter("pId");
	String callerId = request.getParameter("callerId");
%>
<table width="1034" border="1" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="178" height="125" valign="top"><img src="images/caduceus.gif" alt="" name="LogoLeft" width="150" height="125" id="LogoLeft" style="background-color: #0033FF" /></td>
    <td width="616" align="center" valign="middle"><h1 align="center">CADUCEUS HOSPITAL </h1></td>
    <td width="231" valign="top"><img src="images/hospital.jpg" alt="" name="LogoRight" width="180" height="119" id="LogoRight" style="background-color: #0033FF" /></td>
  </tr>
  <tr>
    <td height="19" colspan="2" valign="top">Welcome <%=session.getAttribute("Name")%>&nbsp;<%=new java.util.Date() %></td>
  	<td><a href="home.jsp" title="Logout">Logout</a></td>
  </tr>
</table>
<table width="1034" border="1" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  
  <tr>
    <td width="196" valign="top"><p align="left"> <form name="frmSearchByRange" method="post" action="staff2appt.jsp">
    	<table>
    		<tr>
    			<td>
    				<strong>Search For Appointments:</strong>
    			</td>
    		</tr>
    		<tr>
    			<td>
    				<p align="center"><strong>Start Date Range </strong></p>
                 <p align="center"><strong>Year</strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       <select name="cmbStartYear" id="cmbStartYear">
                       <option>2009</option>
                       </select>
                                </p>
                 <p align="center"><strong>Month</strong>&nbsp;&nbsp;&nbsp;
                       <select name="cmbStartMonth" id="cmbStartMonth" onchange="changeNumberofDays('1')">
                         <option>January</option>
                         <option>February</option>
                         <option>March</option>
                         <option>April</option>
                         <option>May</option>
                         <option>June</option>
                         <option>July</option>
                         <option>August</option>
                         <option>September</option>
                         <option>October</option>
                         <option>November</option>
                         <option>December</option>
                       </select>
                   </p>
                 <p align="center"><strong>Date</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       <select name="cmbStartDate" id="cmbStartDate">
                         <option>1</option>
                         <option>2</option>
                         <option>3</option>
                         <option>4</option>
                         <option>5</option>
                         <option>6</option>
                         <option>7</option>
                         <option>8</option>
                         <option>9</option>
                         <option>10</option>
                         <option>11</option>
                         <option>12</option>
                         <option>13</option>
                         <option>14</option>
                         <option>15</option>
                         <option>16</option>
                         <option>17</option>
                         <option>18</option>
                         <option>19</option>
                         <option>20</option>
                         <option>21</option>
                         <option>22</option>
                         <option>23</option>
                         <option>24</option>
                         <option>25</option>
                         <option>26</option>
                         <option>27</option>
                         <option>28</option>
                         <option>29</option>
                         <option>30</option>
                         <option>31</option>
                       </select>
                   </p>
                 <p align="center">&nbsp;</p>
    			</td>
    		</tr>
    		<tr>
    			<td>
    				<p align="center">End Date Range </p>
                 <p align="center">Year &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       <select name="cmbEndYear" id="cmbEndYear">
                         <option>2009</option>
                                            </select>
                                </p>
                 <p align="center">Month &nbsp;&nbsp;&nbsp;
                   <select name="cmbEndMonth" id="select2" onChange="changeNumberofDays('2')">
                     <option>January</option>
                     <option>February</option>
                     <option>March</option>
                     <option>April</option>
                     <option>May</option>
                     <option>June</option>
                     <option>July</option>
                     <option>August</option>
                     <option>September</option>
                     <option>October</option>
                     <option>November</option>
                     <option>December</option>
                   </select>
                 </p>
                 <p align="center">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       <select name="cmbEndDate" id="select3">
                         <option>1</option>
                         <option>2</option>
                         <option>3</option>
                         <option>4</option>
                         <option>5</option>
                         <option>6</option>
                         <option>7</option>
                         <option>8</option>
                         <option>9</option>
                         <option>10</option>
                         <option>11</option>
                         <option>12</option>
                         <option>13</option>
                         <option>14</option>
                         <option>15</option>
                         <option>16</option>
                         <option>17</option>
                         <option>18</option>
                         <option>19</option>
                         <option>20</option>
                         <option>21</option>
                         <option>22</option>
                         <option>23</option>
                         <option>24</option>
                         <option>25</option>
                         <option>26</option>
                         <option>27</option>
                         <option>28</option>
                         <option>29</option>
                         <option>30</option>
                         <option>31</option>
                       </select>
                   </p>
               <p align="center">&nbsp;</p>
    			</td>
    		</tr>
    		<tr>
    			<td>
    				 <input name="cmdSearch" type="submit" id="cmdSearch" value="Search">
    			</td>
    		</tr>
    	</table>
    	</form></td>
    	
    	
    <td width="619" rowspan="2" valign="top"> <p align="center"><strong>List of Visitations </strong></p>
      <table width="606" height="34" border="1" align="left">
      <thead>
        <tr>
          <td width="80"><div align="center"><strong>Visit ID</strong></div></td>
          <td width="80"><div align="center"><strong>Date of Visit</strong></div></td>
           <td width="80"><div align="center"><strong>Start Time</strong></div></td>
          <td width="80"><div align="center"><strong>End Time</strong></div></td>
          <td width="80"><div align="center"><strong>Building</strong></div></td>
          <td width="80"><div align="center"><strong>Room</strong></div></td>
          <td width="80"><div align="center"><strong>View Details</strong></div></td>
        </tr>
        </thead>
         <tbody>
        <%
    	Login lgn = new Login();
        int staffId = 0; //staff session
        int docId = 0; //doctor session
        ResultSet rs;
    	
        if (callerId.equals("patientListforDoc") || (callerId.equals("editPatientVisitforDoc")))
        {
        	docId = Integer.parseInt(session.getAttribute("docId").toString());
        	rs = lgn.getVisitList(docId,"Doctor",patientId);
        }
        else
        {
        	staffId = Integer.parseInt(session.getAttribute("staffId").toString());
        	rs = lgn.getVisitList(staffId,"Staff",patientId);
        }

    	int visitId;
    	java.sql.Date visitDate;
    	java.sql.Time startTime = Time.valueOf("00:00:00");
		java.sql.Time endTime = Time.valueOf("00:00:00");
    	String building;
    	String room;
    	
    	//if (rs != null)
    	//{
    		if (rs.next())
    		{
    			visitId = rs.getInt("VisitId");
    			visitDate = rs.getDate("Date");
    			startTime = rs.getTime("StartTime");
    			endTime = rs.getTime("EndTime");
    			building = rs.getString("Building");
    			room = rs.getString("Room");
    	%>
    		<tr>
    			<td>
    				<%=visitId%>
    			</td>
    			<td>
    				<%=visitDate.toString() %>
    			</td>
    			<td>
    				<%=startTime%>
    			</td>
    			<td>
    				<%=endTime%>
    			</td>
    			<td>
    				<%=building%>
    			</td>
    			<td>
    				<%=room%>
    			</td>
    			<td>
    				<%
    				String url;
    				String linkText;
    				if (callerId.equals("patientListforDoc"))
    				{
    					url = "editPatientVisitforDoc.jsp?vId=" + visitId + "&callerId=visitList";
    					linkText = "Edit ";
    				}
    				else if (callerId.equals("visitSearchResults"))
    				{
    					url = "editPatientVisitforDoc.jsp?vId=" + visitId + "&callerId=doctorHome";
    					linkText = "Edit ";
    				}
    				else if (callerId.equals("editPatientVisitforDoc"))
    				{
    					url = "editPatientVisitforDoc.jsp?vId=" + visitId + "&callerId=visitList";
    					linkText = "Edit";
    					
    				}
    				else //patient/staff/finance
    				{
    					url = "patientVisit.jsp?vId=" + visitId + "&callerId=visitList";
    					linkText = "View ";
    				}
    				%>
    				<a href="<%=url%>"><%=linkText%> Visit Details</a>
    			</td>
    		<tr>
    	<%
    		}
    		
    	//}
    		else //no visitation records available
    		{
    	%>
    			<tr>
    				<td colspan=8><font color="red">No Visitation Records Available For Patient</font></td>
    			</tr>
    			
        <%
    		}
        %>
      
  		<tr>
  			<%
  				String target;
  				target = callerId + ".jsp";
  				if (callerId.equals("editPatientVisitforDoc"))
  				{
  					target = "patientListforDoc.jsp";
  				}
  			%>
    		<td colspan=8><a href="<%=target%>">Back to patient list.</a></td>
    	</tr>
        </tbody>
      </table>      
      <p>&nbsp;</p>    </td>
    <td width="251" height="153" valign="top"><p align="center"><strong> Person Lookup</strong></p>
                  
      <form id="frmSearch" name="frmSearch" method="post" action="">
         <p> 
        <input name="radio" type="radio" value="Doctor">
        Doctor&nbsp;
        <input name="radio" type="radio" value="Patient">
        Patient&nbsp;
        <input name="radio" type="radio" value="Staff">
        Staff </p>
        <p>
        &nbsp;&nbsp;Search for 
          <input type="text" name="TextField1" id="TextField1" />
          <br />
          &nbsp;&nbsp;in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <select name="SearchField1" id="SearchField1">
            <option selected="selected">First Name</option>
            <option>Last Name</option>
            <option>Address</option>
            <option>Phone Number</option>
            <option>Email Address</option>
            <option>Date of Birth</option>
            <option>Health Card</option>
            <option>Freeform Comments</option>
            <option>Current Health</option>
            <option>Patient Id</option>
            <option>Doctor Id</option>
            <option>Staff Id</option>
          </select>
      </p>
        <p class="style5">&nbsp;<em>AND</em></p>
        <p>&nbsp;&nbsp;Search for
          <input type="text" name="TextField2" id="TextField2" />
          <br />
          &nbsp;&nbsp;in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <select name="SearchField2" id="SearchField2">
                      <option selected="selected">First Name</option>
                      <option>Last Name</option>
                      <option>Address</option>
                      <option>Phone Number</option>
                      <option>Email Address</option>
                      <option>Date of Birth</option>
                      <option>Health Card</option>
                      <option>Freeform Comments</option>
                      <option>Current Health</option>
                      <option>Patient Id</option>
                      <option>Doctor Id</option>
                      <option>Staff Id</option>
          </select>
        </p>
        <p>&nbsp;<em class="style5">AND</em></p>
        <p>&nbsp;&nbsp;Search for
          <input type="text" name="TextField3" id="TextField3" />
            <br />
          &nbsp;&nbsp;in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <select name="SearchField3" id="SearchField3">
    <option selected="selected">First Name</option>
    <option>Last Name</option>
    <option>Address</option>
    <option>Phone Number</option>
    <option>Email Address</option>
    <option>Date of Birth</option>
    <option>Health Card</option>
    <option>Freeform Comments</option>
    <option>Current Health</option>
    <option>Patient Id</option>
    <option>Doctor Id</option>
    <option>Staff Id</option>
  </select>
        </p>
        <p align="center">
          <input type="submit" name="Search1" id="Search1" value="Search" />
        </p>
      </form>      </td>
  </tr>
  
  <tr>
    <td valign="top" class="style2"><p align="left"><strong>Quicklinks</strong></p>
      <p><a href="patientListforDoc.jsp">View List of Patients</a></p>
      <p><a href="doc2appt.jsp">View My Appointments</a></p>
      <p><a href="#">Change My Personal Information</a></p>
      <p><a href="http://www.webmd.com">WebMD</a></p>
    <p><a href="#">Last Visit</a></p></td>
    <td height="220" valign="top" class="style2"><p>&nbsp;</p>
    <p>&nbsp;</p></td>
  </tr>
</table>
</body>
</html>